﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IteratorPattern
{
    public class NamesRepository : Container
    {
        private static string[] names = { "Robert", "John", "Julie", "Lora" };
        public Iterator GetIterator()
        {
            return new NameIterator();
        }

        private class NameIterator : Iterator
        {
            int index;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
            public bool HasNext()
            {
                if (this.index < names.Length)
                {
                    return true;
                }

                return false;
            }

            public object Next()
            {
                if (HasNext())
                {
                    return names[index++];
                }

                return null;
            }
        }
    }
}
